<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="表编码" prop="meterNum">
        <el-select
          clearable
          v-model="queryParams.meterNum"
          placeholder="请选择表编码"
        >
          <el-option
            v-for="item in meterList"
            :key="item.id"
            :label="item.meterNum"
            :value="item.meterNum"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="费用周期" label-width="88px" prop="feeCycle">
        <el-date-picker clearable size="small"
          v-model="queryParams.feeCycle" type="month"
          value-format="yyyy-MM"
          placeholder="选择费用周期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['energy:nyCheckSum:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['energy:nyCheckSum:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table :data="nyCheckSumList" row-key="id" @selection-change="handleSelectionChange"
              :tree-props="{children: 'children', hasChildren: 'hasChildren'}" >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="表编码" align="center" prop="meterNum" />
      <el-table-column label="费用周期" align="center" prop="feeCycle" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.feeCycle, '{y}-{m}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="上期度数" align="center" prop="lastValue" />
      <el-table-column label="本期度数" align="center" prop="currentValue" />
      <el-table-column label="实际量" align="center" prop="actualDosage" />
      <el-table-column label="私表总量" align="center" prop="privateSum" />
      <el-table-column label="差值" align="center" prop="diffValue" />
      <el-table-column label="使用企业" align="center" prop="enterpriseName" />
      <!--显示是否已累加-->
      <!--<el-table-column label="是否已累加" align="center" prop="isComputed" :formatter="isComputedFormat" />-->
      <!--<el-table-column label="父id" align="center" prop="pid" />-->
      <!--总表 需要累加 显示操作-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
      <template slot-scope="scope">
        <!--<el-button-->
          <!--size="mini"-->
          <!--type="text"-->
          <!--icon="el-icon-edit"-->
          <!--@click="handleAdd(scope.row)"-->
          <!--v-show="scope.row.isComputed == '0'"-->
          <!--v-hasPermi="['energy:nyCheckSum:edit']"-->
        <!--&gt;累加</el-button>-->
        <el-button
          size="mini"
          type="text"
          icon="el-icon-delete"
          @click="handleDelete(scope.row)"
          v-hasPermi="['energy:nyCheckSum:remove']"
        >删除</el-button>
      </template>
    </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList"/>
  </div>
</template>

<script>
import { listNyCheckSum, getNyCheckSum, delNyCheckSum,updateNyCheckSum,computePlus ,addNyCheckSum} from "@/api/smartParks/energy/energyMeterRading";
import {  listNyMeterAccount,} from "@/api/smartParks/energy/energyMeterSummaryTable";

export default {
  name: "NyCheckSum",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      category:"",
      // 私汇总表格数据
      nyCheckSumList: [],
      meterList: [],
      meterTypes:[{id:'0',type:"水表"},{id:'1',type:"电表"}],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否累加字典
      isComputedOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        meterId: null,
        meterType: '水表',
        meterNum: null,
        category: '总表',
        feeCycle: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    //const meterType = this.$route.query.meterType;
    //总表 查询
    this.getList();
    listNyMeterAccount(this.queryParams).then((response) => {
      this.meterList = response.rows;
    });
  },
  methods: {
    /** 查询私汇总列表 */
    getList() {
      this.loading = true;
      listNyCheckSum(this.queryParams).then(response => {
        this.nyCheckSumList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 是否累加字典翻译
    // isComputedFormat(row, column) {
    //   if(row.isComputed == '0'){
    //     return "否";
    //   }else{
    //     return "是";
    //   }
    //
    // },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        meterId: null,
        meterNum: null,
        feeCycle: null,
        diffValue: null,
        actualDosage: null,
        isComputed: null,
        privateSum: null,
        createTime: null,
        createBy: null,
        pid: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    handleCompute(){
      computePlus(this.queryParams).then(response => {
        //if(response.code == '200'){
          this.msgSuccess("计算成功");
          this.getList();
        //}
      });
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除私汇总编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delNyCheckSum(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },

    /** 累加按钮操作 */
    handleAdd(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认累加到分摊池', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return addNyCheckSum(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("累加成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('energy/nyCheckSum/export', {
        ...this.queryParams
      }, `energy_nyCheckSum.xlsx`)
    }
  }
};
</script>
